$(document).ready(function () {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules : {
            name : {required : true,},
            sort : {required : true,},
            type : {required : true,},
        },
        messages : {
            name : {required : icon + "请输入名称"},
        	sort : {required : icon + "请输入排序号"},
        	type : {required : icon + "请输入机构类型"},
        }
    });
});
$.validator.setDefaults({
	submitHandler : function() {
        $.ajax({
            cache : false,
            type : "POST",
            url : ctx + "a/office/update",
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {parent.layer.alert("Connection error", {offset: "100px"});},
            success : function(data) {
                if (data.result == "success") {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    parent.layer.alert(data.msg, {offset: "100px"})
                }
            }
        });
	}
});

function openOffice(){
	layer.open({
		type:2,
		title:"选择机构",
		area : [ '300px', '450px' ],
		content: ctx + "a/office/tree",
	})
}

function loadOffice(parentId, parentName){
	$("#parentId").val(parentId);
	$("#parentName").val(parentName);
}
